package com.ssyt.yec.common.util;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.log4j.Logger;

import com.ssyt.yec.common.Constant;

/**
 * Log工具类
 * 
 * @author Hsu.
 * @since 2016年3月3日
 */
public class LogUtil {

	private static final Logger LOG = Logger.getLogger(LogUtil.class);

	/**
	 * 用于对象打印，属性会在控制以多行形式显示出来
	 * 
	 * @param obj
	 */
	public static void printObject(Object obj) {
		d(LOG, ToStringBuilder.reflectionToString(obj,
				ToStringStyle.MULTI_LINE_STYLE));
	}

	/**
	 * Log4j常用的三种日志输出
	 */
	public static void e(Logger logger, String message, Exception e) {
		validateLogger(logger);

		logger.error(message, e);
	}

	public static void i(Logger logger, String message) {
		validateLogger(logger);

		if (logger.isInfoEnabled()) {
			logger.info(message);
		}
	}

	public static void d(Logger logger, String message) {
		validateLogger(logger);

		if (logger.isDebugEnabled()) {
			logger.debug(message);
		}
	}

	private static void validateLogger(Logger logger) {
		Validate.notNull(logger, "logger" + Constant.VALIDATE_NOT_NULL);
	}
}
